home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The PC-SIG Library 9
/
The PC-SIG Library on CD ROM - Ninth Edition.iso
/
301_400
/
DISK0353
/
DISK0353.ZIP
/
DECIHEX.ASM
< prev
next >
Wrap
Assembly Source File
|
1984-09-14
|
3KB
|
72 lines
; from ASSEMBLY LANGUAGE PRIMER FOR THE IBM PC & XT
; by Robert LaFore
; modified to be compilable by CHASM (disk # 37)
;MAIN PART OF PROGRAM
;Connects procedures together
repeat call decibin ;keyboard to binary
call crlf ;print cr and lf
call binihex ;binary to screen
call crlf ;print cr and lf
jmps repeat ;do it again
;+++++++++++++++++++++++++++++++++++++++++++
;PROCEDURE TO CONVERT DEC ON KEYBD TO BINARY
;result is left in bx register
decibin proc near
mov bx,0 ;clear bx for number
; get digit from keyboard, convert to binary
newchar mov ah,1 ;keyboard input
int 21h ;call DOs
sub al,30h ;ASCII to binary
jl exit ;jump if <0
cmp al,9 ;> 9d?
jg exit ;if so, not a dec. digit
cbw ;byte in al to word in ax
;(digit is now in ax)
;Multiply number in bx by 10 decimal
xchg ax,bx ;trade digit and number
mov cx,10 ;put 10d in cx
mul ax,cx ;number times 10 (ChAsm wants "ax")
xchg ax,bx ;trade number and digit
;add digit in ax to number in bx
add bx,ax ;add digit to number
jmps newchar ;get next digit
exit
ret ;return from decibin
endp
;+++++++++++++++++++++++++++++++++++++++++++
;PROCEDURE TO CONVERT BINARY NUMBER IN BX TO HEX ONSCREEN
binihex proc near ;
mov ch,4 ;number of digits
rotate mov cl,4 ;set count to 4 bits
rol bx,cl ;left digit to right
mov al,bl ;move to al
and al,0fh ;mask off left digit
add al,30h ;convert to ascii
cmp al,3ah ;is it > 9?
jl printit ;if not, printit
add al,7h ;digit is A to F
printit
mov dl,al ;put ascii chr in dl
mov ah,2 ;display output function
int 21h ;DOS call
dec ch ;done 4 yet?
jnz rotate ;if not, go back
ret ; return from binihex
endp
;+++++++++++++++++++++++++++++++++++++++++++
;PROCEDURE TO PRINT CR AND LF ONSCREEN
crlf proc near
mov dl,0dh ;carriage return
mov ah,2 ;display function
int 21h ;DosCall
mov dl,0ah ;linefeed
mov ah,2 ;display function
int 21h ;DosCall
ret ;return from crlf
endp
;+++++++++++++++++++++++++++++++++++++++++++
;decihex ends
;+++++++++++++++++++++++++++++++++++++++++++